//
//  MYGResumeOtherCell.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/5/24.
//

import UIKit

class MYGResumeOtherCell: UITableViewCell {

    var type :String = ""
    var isEN:Bool = false
    var model:MYGResumeAllType? {
        didSet {
            guard let item = model else{return}
           
            if isEN == true {
                contentLab.text = item.en_title
            }else {
                contentLab.text = item.title
            }

            let yearStart = item.dateStart
            let yearEnd = item.dateEnd
            timeView.text = "\(yearStart)-\(yearEnd)"
            
//
            if (type == "GoodAt"){// 专业擅长
//                let created_at = item.created_at.double()
                contentLab.text = isEN ? item.en_content : item.content
//                timeView.text = "\(created_at?.toTimeString(formatter:"yyyy-MM-dd") ?? "")"
                timeView.text = ""
            }
            let text =  timeView.text ??  ""
            let size: CGSize = getStringSize(font: .regular(14), viewSize:  CGSize(width: CGFloat(MAXFLOAT), height: SCALEWIDTH(20)), str:text )
            timeView.snp.updateConstraints { make in
                make.width.equalTo(size.width + 10)
            }
            //else if (type == "Honors"){//个人荣誉
//                let yearStart = item.dateStart
//                let yearEnd = item.dateEnd
//                timeView.text = "\(yearStart)-\(yearEnd)"
//                
//            }else if (type == "Clinical"){//临床实验
//                let yearStart = item.dateStart
//                let yearEnd = item.dateEnd
//                timeView.text = "\(yearStart)-\(yearEnd)"
//                
//            }else if (type == "Internship"){//实习经验
//                let yearStart = item.dateStart
//                let yearEnd = item.dateEnd
//                timeView.text = "\(yearStart)-\(yearEnd)"
//                
//            } else if (type == "Publish"){//出版
//                let yearStart = item.dateStart
//                let yearEnd = item.dateEnd
//                timeView.text = "\(yearStart)-\(yearEnd)"
//                
//            }else if (type == "Patent"){//获得专利
//                let yearStart = item.dateStart
//                let yearEnd = item.dateEnd
//                timeView.text = "\(yearStart)-\(yearEnd)"
//              
//            } else if (type == "Custom"){//自定义模块
//                let yearStart = item.dateStart
//                let yearEnd = item.dateEnd
//                timeView.text = "\(yearStart)-\(yearEnd)"
//            }
//
        }
        
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        configUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - UI
    private func configUI() {
        contentView.backgroundColor = .white
        contentView.addSubview(contentLab)
        contentView.addSubview(timeView)
        contentLab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(30)
            make.centerY.equalToSuperview()
            make.right.equalTo(timeView.snp.left)
//            make.height.equalTo(23)
        }
        
        timeView.snp.makeConstraints { make in
            make.centerY.equalTo(contentLab)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(20)
            make.width.equalTo(100)
        }
    }
    
    private lazy var contentLab:UILabel = {
        let tw = UILabel()
        tw.text = ""
        tw.textColor = .rgba(10, 10, 10, 1)
        tw.font = .regular(16)
        tw.numberOfLines = 0
        return tw
    }()
    
    private lazy var timeView:UILabel = {
        let tw = UILabel()
        tw.text = ""
        tw.textColor = .rgba(132, 132, 132, 1)
        tw.font = .regular(14)
        return tw
    }()
    
   private func timestampToDate(timestamp: TimeInterval) -> String {
        let date = Date(timeIntervalSince1970: timestamp)
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd"
        return formatter.string(from: date)
    }
}
